﻿@{
    ViewBag.Title = "MemberTime";
}

@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script> 
}
   <div class="mini-splitter" style="width:100%;height:100%;">
    <div size="270" showcollapseButton="true">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table>
                <tr>
                    <td width ="80px" align="right">类型名称: </td>
                    <td width ="110px" ><input class="mini-textbox" id ="TreeKey" width ="110px" name = "TreeKey" onkeypress="setkeyPressCls()"/></td>
                    <td width ="80px" align="center">
                        <a class="mini-button" iconCls="icon-search" onclick="findtree" plain="true">搜索</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="mini-fit">
           <ul id="tree1" class="mini-tree" style="width:100%;" expandOnLoad="0"
              textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">        
           </ul>
        </div>
    </div>
       
    <div showCollapseButton="true">
        @Html.Partial("~/Views/Modular/ToolBarBaseEx.cshtml")
        <table>
            <tr>
                <td width ="100px" align="right">编码或名称: </td>
                <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()"/></td>
                <td width ="100px" align="center">
                    <a class="mini-button" iconCls="icon-search" onclick="search(0)" plain="true">查询</a>
                </td>
            </tr>
        </table>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="../Member/GetServiceList"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client">
                <div property="columns">
                    <div type="checkcolumn"></div>
                    <div type="indexcolumn" width="40" headerAlign="center">序号</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">项目编码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">项目名称</div>                    
                    <div field="FCardTypeName" name="FCardTypeName" width="90" headeralign="center" allowsort="true">使用期限</div>                    
                    <div field="FAmount" name="FAmount" width="70" headeralign="center" numberFormat="#,0.00" align="right" allowsort="true">销售金额</div>                    
                    <div field="FIntegral" name="FIntegral" width="70" headeralign="center" numberFormat="#" align="right" allowsort="true">每次积分</div>
                    <div field="FRebateValue" name="FRebateValue" width="70" headeralign="center" numberFormat="#,0.00" align="right" allowsort="true">提成金额</div>
                    <div field="FDiscount" name="FDiscount" width="70" headeralign="center" numberFormat="#,0.00" align="right" allowsort="true">会员折扣</div>
                    <div field="FEffectDays" name="FEffectDays" width="70" headerAlign="center" align="right" allowSort="true">有效天数</div>
                    <div field="FStartDate" name="FStartDate" width="80" headerAlign="center" align="right" allowSort="true">开始日期</div>
                    <div field="FEndDate" name="FEndDate" width="80" headerAlign="center" align="right" allowSort="true">结束日期</div>
                    <div field="FStateName" name="FStateName" width="70" headerAlign="center" allowSort="true">状态</div>
                    <div field="FClassName" name="FClassName" width="90" headeralign="center" allowsort="true">会员分类</div>
                    <div field="FStockName" name="FStockName" width="150" headeralign="center" allowsort="true">门店名称</div>
                    <div field="FCorpName" name="FCorpName" width="120" headeralign="center" allowsort="true">所属商户</div>
                    <div field="FRemark" name="FRemark" width="120" headerAlign="center" allowSort="true">备注</div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    mini.parse();
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");

    //通用shown自动调用些方式
    function FormShown() {
    
        LoadListTree();
        tree.on("nodeselect", function (e) {
            LoadListData(0);
        });
        LoadListData(0);
    }

    function setkeyPress() {
        if (event.keyCode == 13) {
            search(0);
        }
    }

    //加载分类树
    function LoadListTree() {
        var sSystemAppID = parent.window.getSystemAppID();
        $.post('GetMemberClassTree', { mjson: sSystemAppID }, function (data) {
            tree.loadList(mini.decode(data));
            tree.select(0);
        });
    }


    //加载资料列表
    function LoadListData(mdatatype) {
        var sSystemAppID = parent.window.getSystemAppID();
        var mload = tree.getData();
        if (mload.length > 0) {
            var node = tree.getSelectedNode();
            var classid = node.FItemID;
            var json = "[{";
            json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
            json = json + "'mClassID':" + "'" + classid + "',";
            json = json + "'mNumber':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
            json = json + "'mDatatype':" + "'" + mdatatype + "'";
            json = json + "}]";            
            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;
        }
    }

    //搜索资料列表
    function search(mdatatype) {
        LoadListData(mdatatype);
    }


    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        var node = tree.getSelectedNode();
        if (node.FItemID == 0) {
            mini.alert("请选择一个会员分类再新增");
            return;
        }
        if (node.FItemID < 0) {
            mini.alert("请选择一个会员分类再新增");
            return;
        }
        mini.open({
            url: "/Member/MemberServiceInfo",
            title: "会员服务资料", width: 740, height: 380,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0", FClassID: node.FItemID, FClassNumber: node.FNumber, FClassName: node.FName };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }


    //修改资料
    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var row = grid.getSelected();
        if (row.FModifyFlag == 0) {
            mini.alert("选择项目不属于本商户不能修改。");
            return;
        }
        if (row) {
            mini.open({
                url: "/Member/MemberServiceInfo",
                title: "会员服务资料", width: 740, height: 380,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除资料
    function removeInfo() {
        var row = grid.getSelected();
        if (row.FModifyFlag == 0) {
            mini.alert("选择项目不属于本商户不能删除。");
            return;
        }
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        SetRemoveRows();
                        LoadListTree(0);
                    }
                });
        } else {
            mini.alert("请选要删除的记录");
        }
    }

    function SetRemoveRows() {
        var FSystemAppID = parent.window.getSystemAppID();
        var rows = grid.getSelecteds();
        var json = "[";
        for (var i = 0; i < rows.length; i++) {
            if (i > 0)
                json = json + ',';
            js = '{"FItemID":' + rows[i].FItemID + '}';
            json = json + js
        }
        json = json + "]";
        if (json.length < 8) {
            mini.alert("没有要删除的数据！");
            return;
        }
        $.post("RemoveServiceRows", { json: json, mSystemAppID: FSystemAppID }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
            }
            else {
                mini.alert("异常：" + ret.error);
            }
        });
    }

    
    function setkeyPressCls() {
        if (event.keyCode == 13) {
            findtree();
        }
    }

    function findtree() {
        var key = mini.get("TreeKey").getValue();
        if (key == "") {
            tree.clearFilter();
        } else {
            key = key.toLowerCase();
            tree.filter(function (node) {
                var text = node.FName ? node.FName.toLowerCase() : "";
                if (text.indexOf(key) != -1) {
                    return true;
                }
            });
        }
    }

    function printBill() {
        var url = "../Report/PrintReport";
        mini.open({
            url: url,
            title: "打印", width: 1000, height: 700,
            onload: function () {
                var iframe = this.getIFrameEl();
                var NoneDisplayCol = [0];
                iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, "会员计次表");
            }
        });
    }

</script>